﻿Public Class KhachHang
    Public Shared Function them(ByVal tenkh As String, ByVal diachi As String, ByVal dienthoai As String, ByVal cmnd As String) As Boolean
        tenkh = EscapeString(tenkh)
        diachi = EscapeString(diachi)
        dienthoai = EscapeString(dienthoai)
        cmnd = EscapeString(cmnd)
        Return db.Query("INSERT INTO KhachHang(TenKH,DiaChi,DienThoai,CMND)VALUES(N'" + tenkh + "',N'" + diachi + "','" + dienthoai + "','" + cmnd + "')")
    End Function
    Public Shared Function dskh() As DataTable
        Return db.QueryTable("SELECT * FROM KhachHang")
    End Function
    Public Shared Function capnhat(ByVal makh As String, ByVal tenkh As String, ByVal diachi As String, ByVal dienthoai As String, ByVal cmnd As String) As Boolean
        makh = EscapeString(makh)
        tenkh = EscapeString(tenkh)
        dienthoai = EscapeString(dienthoai)
        cmnd = EscapeString(cmnd)
        Return db.Query("UPDATE KhachHang SET TenKH = N'" & tenkh & "',DiaChi = N'" & diachi & "',DienThoai = N'" & dienthoai & "',CMND = '" + cmnd + "' where MaKH = '" & makh & "'")
    End Function
    Public Shared Function xoa(ByVal makh As String) As Boolean
        makh = EscapeString(makh)
        Return db.Query("DELETE FROM KhachHang WHERE MaKH = '" + makh + "'")
    End Function
    Public Shared Function timkiem(ByVal tukhoa As String) As DataTable
        tukhoa = EscapeString(tukhoa)
        Return db.QueryTable("SELECT * FROM KhachHang WHERE MaKH like '%" & tukhoa & "%' or TenKH like N'%" & tukhoa & "%'or DiaChi like N'%" & tukhoa & "%' or DienThoai like '%" & tukhoa & "%'or CMND like '%" & tukhoa & "%'")
    End Function
End Class
